package com.base.cn.platform.os.controller.classes.topic.type;


import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.classes.topic.type.ClassesTopicType;
import com.base.cn.platform.os.service.classes.topic.type.ClassesTopicTypeBiz;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


/**
 * 班级话题分类
 *
 * @author zjh
 * @since 2019-05-20
 */
@RestController
@RequestMapping("/course")
public class ClassesTopicTypeController extends BaseController {
    @Autowired
    ClassesTopicTypeBiz classesTopicTypeBiz;

    /**
     * 查询班级话题分类列表
     * @param type       查询
     * @param currentPage  当前页
     * @param pageSize     每页数据量
     * @return 班级话题分类列表
     */
    @RequestMapping("/findClassesTopicTypePage")
    public   PageInfo<ClassesTopicType> findClassesTopicTypePage(@RequestBody ClassesTopicType type,
                                                                 @RequestParam("currentPage") int currentPage,
                                                                 @RequestParam(value = "pageSize") Integer pageSize){
        Pagination pagination =new Pagination();
        pagination.setCurrentPage(currentPage);
        pagination.setPageSize(pageSize);
        return classesTopicTypeBiz.findClassesTopicTypePage(type,pagination);
    }


    /**
     * 查询班级话题分类
     * @param classesId  查询
     * @return 班级话题分类
     */
    @RequestMapping("/getClassesTopicType")
    public List<Map<String,Object>> getClassesTopicType(@RequestParam("classesId") BigDecimal classesId){

        return classesTopicTypeBiz.getClassesTopicType(classesId);
    }

    @RequestMapping("/saveClassesTopicType")
    public  Map<String,Object> saveClassesTopicType(@RequestBody ClassesTopicType type){
        if(DataUtil.idIsNotNull(type.getId())){
            classesTopicTypeBiz.updateById(type,null);
        }else{
            classesTopicTypeBiz.save(type);
        }
    return ResultUtil.SUCCESS("保存成功");
    }


    /**
     * 新建类型
     * @return
     */
    @RequestMapping("/updateTopicTypeStatus")
    @ResponseBody
    public Map<String,Object> updateTopicTypeStatus(@RequestParam("ids") String ids,
                                                    @RequestParam(value = "status") int status){

        ids = StringUtils.subHeadTailString(ids, ",");
        if(StringUtils.isEmpty(ids)){
            return ResultUtil.ERROR("选择要操作的数据");
        }

        classesTopicTypeBiz.updateTopicTypeStatus(ids,status);

        return ResultUtil.SUCCESS("操作成功");
    }


    /**
     * 获取班级状态数据
     * @param classId 班级id
     * @return 班级话题类型
     */
    @RequestMapping("/getClassesTypeNum")
   public List<Map<String,Object>>getClassesTypeNum(@RequestParam(value = "classId",required = false) BigDecimal classId,@RequestParam(value = "userId",required = false) BigDecimal userId){

     return    classesTopicTypeBiz.getClassesTypeNum(classId,userId);
    }


}
